Make the alignment configurable - #1379
Conversation
Add two experimental config options: MLD_CONFIG_ALIGN sets the alignment of large buffers and structures in bytes, MLD_CONFIG_ALIGN_ATTRIBUTE replaces the declarator prefix for compilers whose spelling mldsa-native does not know. MLD_DEFAULT_ALIGN, MLD_ALIGN and MLD_ALIGN_UP derive from them. The x86_64 and AArch64 backends reject an alignment below what their load and store instructions require. MLD_TOTAL_ALLOC_* is measured for the default alignment, so it is no longer defined once the alignment is customized, and the allocation test skips itself in that case. - Partially addresses #1346 Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
8c86285 to
b64cbd8
Compare
CBMC Results (ML-DSA-65, REDUCE-RAM)
Full Results (210 proofs)
|
CBMC Results (ML-DSA-44, REDUCE-RAM)
Full Results (210 proofs)
|
CBMC Results (ML-DSA-44)
Full Results (210 proofs)
|
CBMC Results (ML-DSA-87, REDUCE-RAM)
Full Results (210 proofs)
|
CBMC Results (ML-DSA-65)
Full Results (210 proofs)
|
CBMC Results (ML-DSA-87)
Full Results (210 proofs)
|
| * Set this only to change the alignment. Wherever mldsa-native knows a | ||
| * declarator prefix for the compiler, that prefix follows the new value | ||
| * automatically; otherwise set MLD_CONFIG_ALIGN_ATTRIBUTE as well. |
There was a problem hiding this comment.
It's not clear to me what "herever mldsa-native knows a declarator prefix for the compiler, that prefix follows the new value automatically" means. Can you rephrase?
| * alignment-sensitive load and store instructions; this is enforced at | ||
| * compile time. |
There was a problem hiding this comment.
It should be clarified if this means a silent alignment bump or a rejection.
| * | ||
| * Declarator prefix aligning the declared object. | ||
| * | ||
| * Set this only if mldsa-native knows no spelling for your compiler. Without |
There was a problem hiding this comment.
It's unclear what "Set this only if mldsa-native knows no spelling for your compiler." means.
| #define MLD_DEFAULT_ALIGN MLD_CONFIG_ALIGN | ||
| #else | ||
| #define MLD_DEFAULT_ALIGN 32 |
There was a problem hiding this comment.
MLD_DEFAULT_ALIGN is perhaps no longer the right name?
| /* This backend loads and stores polynomials through Q registers, which fault | ||
| * on operands that are not 16-byte aligned if alignment checking is on. */ | ||
| #if MLD_DEFAULT_ALIGN < 16 | ||
| #error Bad configuration: The AArch64 backend requires MLD_CONFIG_ALIGN to be at least 16 |
| /* This backend loads and stores polynomials with vmovdqa, which faults on | ||
| * operands that are not 32-byte aligned. */ | ||
| #if MLD_DEFAULT_ALIGN < 32 | ||
| #error Bad configuration: The x86_64 backend requires MLD_CONFIG_ALIGN to be at least 32 |
There was a problem hiding this comment.
Perhaps say why here, too
|
|
||
| /* This backend loads and stores polynomials through Q registers, which fault | ||
| * on operands that are not 16-byte aligned if alignment checking is on. */ | ||
| #if MLD_DEFAULT_ALIGN < 16 |
There was a problem hiding this comment.
We should also catch the case where we don't know an alignment declarator. In that case, one should arguably refuse to build the backends. One way to do this would be to check first if an alignment declarator is known, and if not, set the alignment to 1.
There was a problem hiding this comment.
Overall this looks good, thanks @mkannwischer! Some documentation nits in comments. We should also use this opportunity to fix the pre-existing defect that if no alignment declarator is known, we silently build the backends without alignment constraints.
Add two experimental config options: MLD_CONFIG_ALIGN sets the alignment of large buffers and structures in bytes, MLD_CONFIG_ALIGN_ATTRIBUTE replaces the declarator prefix for compilers whose spelling mldsa-native does not know. MLD_DEFAULT_ALIGN, MLD_ALIGN and MLD_ALIGN_UP derive from them.
The x86_64 and AArch64 backends reject an alignment below what their load and store instructions require.
MLD_TOTAL_ALLOC_* is measured for the default alignment, so it is no longer defined once the alignment is customized, and the allocation test skips itself in that case.